package com.example.tests.lesson1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.Properties;


public class Variables {

	public static String username;
	
	public static String password;
	
	public static String proName;

	public static String proKey;

	public static String proOwner;
	
	public static String proDescription;
	
	public static String proNotification;
	
	public static String proPermission;
	
	public static String proSecurity;
	
	private static Properties pro;
	
	static {
		pro = new Properties();
		try {
			FileInputStream inputStr = new FileInputStream(new File("config.properties"));
			pro.load(inputStr);
			username = pro.getProperty("username");
			password = pro.getProperty("password");
			
			//Project relevant variables
			proName = pro.getProperty("project_name");
			proKey = pro.getProperty("project_key");
			proOwner = pro.getProperty("project_owner");
			proDescription = pro.getProperty("project_description");
			proNotification = pro.getProperty("project_notificatioin");
			proPermission = pro.getProperty("project_permission");
			proSecurity = pro.getProperty("project_security");
			updateEncoding();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
	private static void updateEncoding(){
		try {
			proName = new String(proName.getBytes("GBK"), "UTF-8");
			proDescription = new String(proDescription.getBytes("GBK"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	private static void changeEncoding(){
		Class clazz = Variables.class;
		try {
			Object obj = clazz.newInstance();
			Field[] fields = obj.getClass().getDeclaredFields();
			for(Field field : fields){
//				field.
			}
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
	
	
}
